package com.example.smartcity.ui.smartCity.Adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.smartcity.R
import com.example.smartcity.logic.utils.Toast.Companion.showToast
import com.example.smartcity.ui.smartCity.activitytModule.SmShowActivity
import com.example.smartcity.ui.smartCity.model.Sm

/**
 *
 *  ANDROID STUDIO -version 2022.19
 *  项目名: SmRecyclerViewAdapter
 *  创建时间: 2023/2/15 21:06
 *  CodeAuthor: ikun
 *  email: 2506789532@qq.com
 **/
class SmRecyclerViewAdapter(val data: List<Sm>) : RecyclerView.Adapter<SmRecyclerViewAdapter.ViewHolder>(){
    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        val smTitle = view.findViewById<TextView>(R.id.SmTitle)
        val smContend = view.findViewById<TextView>(R.id.SmContend)
        val smTime = view.findViewById<TextView>(R.id.SmTime)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.recyclerview_item_sm, parent, false)
        val view = ViewHolder(root)

        view.itemView.setOnClickListener {
            parent.context.startActivity(Intent(parent.context, SmShowActivity::class.java).apply {
                putExtra("title", view.smTitle.text.toString())
                putExtra("contend", view.smContend.text.toString())
                putExtra("time", view.smTime.text.toString())
            })

        }

        return view
    }

    override fun getItemCount() = data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val list = data[position]
        holder.smTitle.text = list.SmTitle
        holder.smContend.text = list.SmContend
        holder.smTime.text = list.SmTime
    }
}